package logic

import (
	"fmt"
	"context"
	// "database/sql"

	"e4ting/internal/svc"
	"e4ting/internal/model"
	"e4ting/pb/e4ting"

	"github.com/zeromicro/go-zero/core/logx"
)

type NewTypeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNewTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NewTypeLogic {
	return &NewTypeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *NewTypeLogic) NewType(in *e4ting.NewTypeReq) (*e4ting.OneTypeRes, error) {
	// todo: add your logic here and delete this line

	fmt.Printf("%+v\n", in)

	data := model.Types{
		Name: in.Name,
		Detail: in.Detail,
	}

	err := l.svcCtx.TypeModel.Insert(l.ctx, &data)
	if err != nil {
		return &e4ting.OneTypeRes{
			Code: 400,
			Err: err.Error(),
		}, nil
	}

	// item,_ := l.svcCtx.TypeModel.FindOne(l.ctx, data.Id)
	return &e4ting.OneTypeRes{
		Code: 200,
		Data: ToTypeData(data),
	}, nil
}
